<template>
  <div>
    <div class="loading-box" v-if="isLoading">
      <loading></loading>
    </div>
    <div class="ads-list">
      <ad-list-item
        v-for="(item, index) in ads"
        :data="item"
        :key="index"
        @click.native="toDetail(item)">
      </ad-list-item>
    </div>
  </div>
</template>
<script>
import AdListItem from '@/components/AdListItem'
export default {
  name: 'list',
  props: {
    id: {
      type: Number,
      default: 1
    }
  },
  components: {
    AdListItem
  },
  created () {
    this.isLoading = true
    this.$api.get(`ads/ad_item/${this.id}`).then(req => {
      this.ads = req.data
      this.isLoading = false
    })
  },
  data () {
    return {
      isLoading: false,
      ads: []
    }
  },
  methods: {
    toDetail (item) {
      this.$router.push({ name: 'Detail', params: { id: item.app_store_id } })
    }
  }
}
</script>
<style lang="scss" scoped>
.ads-list{
  display: flex;
  flex-wrap: wrap;
  padding: 5px;
}
</style>
